package com.tanhua.app.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tanhua.app.service.RecommentService;
import com.tanhua.domain.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;


@RestController
@RequestMapping(value = "/tanhua")
public class TanHuaController {
    @Autowired
    private RecommentService recommentService;

    @GetMapping(value = "/todayBest", name = "最高缘分值今日佳人")
    public ResponseEntity todayBest(){
        return recommentService.findMaxScore(UserHolder.getUser().getId());
    }

    @GetMapping(value = "/recommendation", name = "今日佳人分页列表")
    public ResponseEntity recommendation(Integer page,Integer pagesize) throws ClientException, IOException {
        return recommentService.queryTodayBestList(page,pagesize);
    }

    @GetMapping(value = "/{id}/personalInfo", name = "佳人详情")
    public ResponseEntity personalInfo(@PathVariable("id") Long jrid) throws ClientException, IOException {
        return recommentService.personalInfo(jrid);
    }


    @GetMapping(value = "/strangerQuestions", name = "查询佳人的陌生人问题")
    public ResponseEntity strangerQuestions(Long userId) throws ClientException, IOException {
        return recommentService.strangerQuestions(userId);
    }

    @PostMapping(value = "/strangerQuestions", name = "回复陌生人问题")
    public ResponseEntity toStrangerQuestions(@RequestBody Map map) throws ClientException, IOException {
        Integer jrId =Integer.parseInt(map.get("userId").toString());
        String info =(String)map.get("reply");
        return recommentService.toStrangerQuestions(jrId,info);
    }

}

